#ifndef AVRPORT_H_INCLUDED
#define AVRPORT_H_INCLUDED
namespace smasher
{

class Port
{
    public:
        // pin oriented operations
        virtual void setPin(uint8_t pin, bool value) = 0;
        virtual bool getPin(uint8_t pin) = 0;
        virtual void setPinAsOutput(uint8_t pin) = 0;
        virtual void setPinAsInput(uint8_t pin) = 0;
        virtual void togglePin(uint8_t pin) = 0;

        // whole port oriented operations. Handle with care.
        virtual void setValue(uint8_t value) = 0;
        virtual uint8_t getValue() = 0;
        virtual void setDataDirection(uint8_t value) = 0;
};

class PortD : public Port
{
    public:
        virtual void setPin(uint8_t pin, bool value)
        {
            if(value == true)
            {
                PORTD = PORTD | _BV(pin);
            }
            else
            {
                PORTD = PORTD & (~_BV(pin));
            }
        }
        virtual bool getPin(uint8_t pin)
        {
            if((PORTD & _BV(pin)) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        virtual void setPinAsOutput(uint8_t pin)
        {
            DDRD = DDRD | _BV(pin);
        }
        virtual void setPinAsInput(uint8_t pin)
        {
            DDRD = DDRD & (~_BV(pin));
        }
        virtual void togglePin(uint8_t pin)
        {
            PORTD = PORTD ^ _BV(pin);
        }
        virtual void setValue(uint8_t value)
        {
            PORTD = value;
        }
        virtual uint8_t getValue()
        {
            return PORTD;
        }
        virtual void setDataDirection(uint8_t value)
        {
            DDRD = value;
        }
};


}
#endif // AVRPORT_H_INCLUDED
